package com.zjhome.itoken.common.dto;

import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
public class BaseResult  {
	public static final String RESULT_OK = "ok";
	public static final String RESULT_NOT_OK = "not_ok";
	public static final String SUCCESS = "成功操作";
	
	private String result;
	private Object data;
	private String success;
	private Cursor curosr;
	private List<Error> errors;
	
	public static BaseResult ok() {
		return createResult(RESULT_OK, null, SUCCESS, null, null);
	}
	
	public static BaseResult ok(Object data) {
		return createResult(RESULT_OK, data, SUCCESS, null, null);
	}
	
	public static BaseResult notOk(List<BaseResult.Error> errors) {
		return createResult(RESULT_NOT_OK, null, "", null, errors);
	}
	
	/**
	 * @param result
	 * @param data
	 * @param success
	 * @param curosr
	 * @param errors
	 * @return
	 */
	public static BaseResult createResult(String result, Object data, String success, Cursor curosr, List<Error> errors) {
		BaseResult baseResult = new BaseResult();
		baseResult.setResult(result);
		baseResult.setData(data);
		baseResult.setSuccess(success);
		baseResult.setCurosr(curosr);
		baseResult.setErrors(errors);
		return baseResult;
	}
	
	@Data
	public static class Cursor {
		private int total;
		private int offset;
		private int limit;		
	}
	
	@Data
	@AllArgsConstructor
	public static class Error {
		private String field;
		private String message;
	}
}
